﻿using CommunityToolkit.Mvvm.ComponentModel;
using Koala.Pro.Common;
using Koala.Pro.Core.Dto;
using Koala.Pro.Core.Models;
using Koala.Pro.Models;
using Koala.Pro.Services;

namespace Koala.Pro.ViewModels
{
    public partial class FunctionEditViewModel : BaseEditViewModel<FunctionInfo, string, FunctionPagedDto>
    {
        [ObservableProperty]
        private List<CListItem> roleInfos = new List<CListItem>();

        public FunctionEditViewModel(IFunctionService service)
            : base(service)
        {
            base.Title = "系统功能定义";
        }

        public async Task InitData(string id)
        {
            List<RoleInfo> source = await BLLFactory<IRoleService>.Instance.GetRolesByFunction(id);
            RoleInfos.Clear();
            RoleInfos.AddRange(source.Select((RoleInfo s) => new CListItem(s.Name + "（" + s.CompanyName + "）", s.Id)));
            NotifyChanged("RoleInfos");
        }
    }
}
